package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DsClas;
import com.ruoyi.system.service.IDsClasService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级Controller
 *
 * @author tyro
 * @date 2025-03-30
 */
@RestController
@RequestMapping("/system/clas")
public class DsClasController extends BaseController
{
    @Autowired
    private IDsClasService dsClasService;

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('system:clas:list')")
    @GetMapping("/list")
    public TableDataInfo list(DsClas dsClas)
    {
        startPage();
        List<DsClas> list = dsClasService.selectDsClasList(dsClas);
        return getDataTable(list);
    }

    /**
     * 查询班级列表
     */
    @PreAuthorize("@ss.hasPermi('system:clas:list')")
    @PostMapping("/listByMajorId")
    public TableDataInfo listByMajorId(@RequestBody DsClas dsClas)
    {
        startPage();
        List<DsClas> list = dsClasService.selectDsClasList(dsClas);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @PreAuthorize("@ss.hasPermi('system:clas:export')")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DsClas dsClas)
    {
        List<DsClas> list = dsClasService.selectDsClasList(dsClas);
        ExcelUtil<DsClas> util = new ExcelUtil<DsClas>(DsClas.class);
        util.exportExcel(response, list, "班级数据");
    }

    /**
     * 获取班级详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:clas:query')")
    @GetMapping(value = "/{clasId}")
    public AjaxResult getInfo(@PathVariable("clasId") Long clasId)
    {
        return success(dsClasService.selectDsClasByClasId(clasId));
    }

    /**
     * 新增班级
     */
    @PreAuthorize("@ss.hasPermi('system:clas:add')")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DsClas dsClas)
    {
        return toAjax(dsClasService.insertDsClas(dsClas));
    }

    /**
     * 修改班级
     */
    @PreAuthorize("@ss.hasPermi('system:clas:edit')")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DsClas dsClas)
    {
        return toAjax(dsClasService.updateDsClas(dsClas));
    }

    /**
     * 删除班级
     */
    @PreAuthorize("@ss.hasPermi('system:clas:remove')")
    @Log(title = "班级", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clasIds}")
    public AjaxResult remove(@PathVariable Long[] clasIds)
    {
        return toAjax(dsClasService.deleteDsClasByClasIds(clasIds));
    }
}
